package org.example.route.controller.AdminController;


import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.example.route.model.dto.BaseRequest;
import org.example.route.model.dto.RegisterDTO;
import org.example.route.model.dto.UserDTO;
import org.example.route.model.dto.UserQueryDTO;
import org.example.route.model.pojo.Result;
import org.example.route.model.vo.UserVO;
import org.example.route.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/admin/user")
@Tag(name = "用户管理")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    /**一测**/
    @PostMapping("/add")
    @Operation(summary = "添加用户")
    public Result add(@RequestBody RegisterDTO registerDTO){
        userService.register(registerDTO);
        return Result.success();
    }


/**一测**/
    @PostMapping("/list")
    @Operation(summary = "查询用户")
    public Result<List<UserVO>> list(@RequestBody UserQueryDTO userQueryDTO){
        log.info("查询用户,{}",userQueryDTO);
        List<UserVO> list = userService.list(userQueryDTO);
        return Result.success(list);
    }

    @PostMapping("/banOrFree")
    @Operation(summary = "封禁或解封用户")
    public Result banOrFree(@RequestBody BaseRequest baseRequest){
        log.info("封禁或解封用户,{}",baseRequest.getKey());
        userService.banOrFree(baseRequest);
        return Result.success();
    }


    @PostMapping("/update")
    @Operation(summary = "修改用户")
    public Result update(@RequestBody UserDTO userDTO){
        userService.update(userDTO);
        return Result.success();
    }


    //获取该用户的所有的信息
    @PostMapping("/getCurrentUserInfo")
    @Operation(summary = "获取当前用户信息")
    public Result<UserVO> getCurrentUserInfo(){
        UserVO userVO = userService.getCurrentUserInfo();
        return Result.success(userVO);
    }







}
